package org.infodavid.common.scheduler;

import java.util.List;

import org.infodavid.common.scheduler.commands.IScheduledCommand;
import org.infodavid.common.scheduler.exceptions.SchedulerException;
import org.infodavid.common.services.AbstractService;
import org.joda.time.DateTime;

/**
 * The Class SchedulerService.
 */
public abstract class SchedulerService extends AbstractService<SchedulerException> {

	/**
	 * Instantiates a new service.
	 * @throws Exception the exception
	 */
	protected SchedulerService() throws Exception {
		super();
	}

	/**
	 * New command instance.
	 * @param dataClass the data class
	 * @return the i scheduled command
	 */
	public abstract IScheduledCommand newCommandInstance();

	/**
	 * Schedule.
	 * @param start the start
	 * @param commands the commands
	 * @throws SchedulerException the scheduler exception
	 */
	public abstract void schedule(DateTime start, IScheduledCommand... commands)
	    throws SchedulerException;

	/**
	 * Reschedule.
	 * @param start the start
	 * @param commands the commands
	 * @throws SchedulerException the scheduler exception
	 */
	public abstract void reschedule(DateTime start, IScheduledCommand... commands)
	    throws SchedulerException;

	/**
	 * Schedule.
	 * @param start the start
	 * @param delayInMs the delay in ms
	 * @param commands the commands
	 * @throws SchedulerException the scheduler exception
	 */
	public abstract void schedule(DateTime start, long delayInMs, IScheduledCommand... commands)
	    throws SchedulerException;

	/**
	 * List running.
	 * @param start the start
	 * @param size the size
	 * @param results the list
	 * @throws SchedulerException the scheduler exception
	 */
	public abstract void listRunning(int start, int size, List<IScheduledCommand> results)
	    throws SchedulerException;

	/**
	 * List scheduled.
	 * @param start the start
	 * @param size the size
	 * @param results the list
	 * @throws SchedulerException the scheduler exception
	 */
	public abstract void listScheduled(int start, int size, List<IScheduledCommand> results)
	    throws SchedulerException;

	/**
	 * Gets the command.
	 * @param key the key
	 * @return the command
	 * @throws SchedulerException the scheduler exception
	 */
	public abstract IScheduledCommand getCommand(String key) throws SchedulerException;

	/**
	 * Cancel.
	 * @param keys the keys
	 * @throws SchedulerException the scheduler exception
	 */
	public abstract void cancel(String... keys) throws SchedulerException;
}
